/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.view;

import java.sql.*;
import oracle.jdbc.pool.OracleDataSource;
/**
 *
 * @author Satellite
 */
class DataHandler {

    String jdbcUrl = "jdbc:oracle:thin:@172.23.9.185:1521:orcl";
    String userid = "MHS105314113";
    String password = "MHS105314113";
//    String jdbcUrl = "jdbc:oracle:thin:@localhost:1521:xe";
//    String userid = "hr";
//    String password = "afterglow";
    Connection conn;
    Statement stmt;
    ResultSet rset;
    String query;
    String sqlString;

    public DataHandler() {
    }

    public void getDBConnection() throws SQLException {
        OracleDataSource ds;
        ds = new OracleDataSource();
        ds.setURL(jdbcUrl);
        conn = ds.getConnection(userid, password);
    }

    public ResultSet getAllEmployees() throws SQLException {
        getDBConnection();
        stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
        query = "SELECT first_name FROM Employees ORDER BY employee_id";
        System.out.println("\nExecuting query: " + query);
        rset = stmt.executeQuery(query);
        return rset;
    }

    public static void main(String[] args) throws SQLException {
        DataHandler datahandler = new DataHandler();
        ResultSet rset = datahandler.getAllEmployees();
        while (rset.next()) {
//            System.out.println(rset.getInt(1) + " " + rset.getString(2) + " "
//                    + rset.getString(3) + " " + rset.getString(4));
            System.out.println(rset.getString(1) + " ");
        }
        datahandler.conn.close();
    }
}
